//主模块

//state
export const state =()=>({
  bNav:false,
  bLoading:false,
});

//mutations
export const mutations = {
  M_UPDATE_NAV(state,payload){
    state.bNav = payload;
  },
  M_update_bLoading(state,payload){
    state.bLoading =  payload;
  },
  M_DEL_ITEM(state,key){
    delete state.key
  }
}

//actions
export const actions = {
  // nuxtServerInit(store,context){
  //   //初始化东西到store当中
  //   //console.log('nuxServerInit',store,context)
  // }
  async nuxtServerInit(store,{app:{$cookies}}){
    //刷新后读取cookie里的信息并验证一次
       try {
       console.log("nuxtServerInit")
       let user = $cookies.get('user')


      if(user){
       //   const res = await this.$axios.post('/api/login/check', user);
       //    if (res.data.result.code === 0){ //服务器JWT验证通过
       //      store.commit('user/M_UPDATE_USER',user) //写入VUX已登录信息
       //    }
          store.commit('user/M_UPDATE_USER',user) //写入VUX已登录信息
       }
    }catch (e) {
         //console.log(e)
    }




  // let user = $cookies.get('user')? $cookies.get('user'):{err:2,msg:'未登录',token:''}
  // //写入到vuex
  // store.commit('user/M_UPDATE_USER',user)
  }
}

export const getters = {
  getNav(state){
    return state.bNav ? '显示':'隐藏'
  }
}
